import pandas as pd
from bson.objectid import ObjectId
from .update_tag import UpdateTag

class UpdateAllTag(UpdateTag):
    def __init__(self):
        super(UpdateAllTag, self).__init__({})
        self.user_ids = self.users.find_ids()

    def update_tag(self):
        count = 0
        for user_id in self.user_ids:
            self.user_id = user_id
            self.zhimas_score()
            self.tag_detail()
            tags_detail = pd.DataFrame(self.tags_detail)
            tags_name = pd.DataFrame({'name': self.tags_list})
            data = tags_detail.merge(tags_name).to_dict('records') # 标签详细信息 list
            self.users.update_one({'_id': ObjectId(self.user_id)}, {'tags': data})
            count += 1
        return {'count': count}